package com.yuanyu.server.impl;

import com.yuanyu.common.util.AssertUtil;
import com.yuanyu.common.util.CopyUtil;
import com.yuanyu.mapper.mysqlMapper.MainTable_Mapper;
import com.yuanyu.mapper.mysqlMapper.Serious_damage_and_quality_assessment.Serious_damage_and_quality_assessment_1_Mapper;
import com.yuanyu.mapper.mysqlMapper.Serious_damage_and_quality_assessment.Serious_damage_and_quality_assessment_2_Mapper;
import com.yuanyu.mapper.mysqlMapper.Serious_damage_and_quality_assessment.Serious_damage_and_quality_assessment_Mapper;
import com.yuanyu.model.dto.Serious_damage_and_quality_assessmentDTO;
import com.yuanyu.model.entity.Serious_damage_and_quality_assessment.Serious_damage_and_quality_assessment;
import com.yuanyu.model.entity.Serious_damage_and_quality_assessment.Serious_damage_and_quality_assessment_1;
import com.yuanyu.model.entity.Serious_damage_and_quality_assessment.Serious_damage_and_quality_assessment_2;
import com.yuanyu.model.vo.Serious_damage_and_quality_assessmentVO;
import com.yuanyu.server.ITestPart4Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
@Transactional
public class TestPart4ServerImpl implements ITestPart4Server {
    @Autowired
    private Serious_damage_and_quality_assessment_Mapper seriousDamageAndQualityAssessmentMapper;
    @Autowired
    private Serious_damage_and_quality_assessment_1_Mapper seriousDamageAndQualityAssessment1Mapper;
    @Autowired
    private Serious_damage_and_quality_assessment_2_Mapper seriousDamageAndQualityAssessment2Mapper;
    @Autowired
    private MainTable_Mapper mainTableMapper;


    @Override
    public String test() {
        return "测试成功";
    }

    @Override
    public String test4(Serious_damage_and_quality_assessmentVO seriousDamageAndQualityAssessmentVO) {
        Serious_damage_and_quality_assessment test = seriousDamageAndQualityAssessmentMapper.selTableTime(seriousDamageAndQualityAssessmentVO.getInput_Case());
        AssertUtil.isNull(test,"Case已存在,如需修改内容请前往后台修改");

        Serious_damage_and_quality_assessment seriousDamageAndQualityAssessment = new Serious_damage_and_quality_assessment();
        Serious_damage_and_quality_assessment_1 seriousDamageAndQualityAssessment1 = new Serious_damage_and_quality_assessment_1();
        Serious_damage_and_quality_assessment_2 seriousDamageAndQualityAssessment2 = new Serious_damage_and_quality_assessment_2();

        CopyUtil.copyClass(seriousDamageAndQualityAssessmentVO,seriousDamageAndQualityAssessment);
        seriousDamageAndQualityAssessment.setCreatedAt(LocalDateTime.now());
        seriousDamageAndQualityAssessment.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(seriousDamageAndQualityAssessmentVO,seriousDamageAndQualityAssessment1);
        CopyUtil.copyClass(seriousDamageAndQualityAssessmentVO,seriousDamageAndQualityAssessment2);

        System.out.println(seriousDamageAndQualityAssessment);
        System.out.println(seriousDamageAndQualityAssessment1);
        System.out.println(seriousDamageAndQualityAssessment2);

        int i = seriousDamageAndQualityAssessmentMapper.addTableTime(seriousDamageAndQualityAssessment);
        int i1 = seriousDamageAndQualityAssessment1Mapper.addTable1(seriousDamageAndQualityAssessment1);
        int i2 = seriousDamageAndQualityAssessment2Mapper.addTable2(seriousDamageAndQualityAssessment2);
        AssertUtil.isTrue(i == 1 && i1 == 1 && i2 == 1,"添加数据出现异常,请检查");
        mainTableMapper.updateByCaseFormStartTime(seriousDamageAndQualityAssessmentVO.getInput_Case());
        return "添加成功";
    }

    @Override
    public String updateTable4(Serious_damage_and_quality_assessmentVO seriousDamageAndQualityAssessmentVO) {
        Serious_damage_and_quality_assessment seriousDamageAndQualityAssessment = new Serious_damage_and_quality_assessment();
        Serious_damage_and_quality_assessment_1 seriousDamageAndQualityAssessment1 = new Serious_damage_and_quality_assessment_1();
        Serious_damage_and_quality_assessment_2 seriousDamageAndQualityAssessment2 = new Serious_damage_and_quality_assessment_2();

        CopyUtil.copyClass(seriousDamageAndQualityAssessmentVO,seriousDamageAndQualityAssessment);
        seriousDamageAndQualityAssessment.setUpdatedAt(LocalDateTime.now());
        CopyUtil.copyClass(seriousDamageAndQualityAssessmentVO,seriousDamageAndQualityAssessment1);
        CopyUtil.copyClass(seriousDamageAndQualityAssessmentVO,seriousDamageAndQualityAssessment2);
        int i = seriousDamageAndQualityAssessmentMapper.updateTableTime(seriousDamageAndQualityAssessment);
        int i1 = seriousDamageAndQualityAssessment1Mapper.updateTable1(seriousDamageAndQualityAssessment1);
        int i2 = seriousDamageAndQualityAssessment2Mapper.updateTable2(seriousDamageAndQualityAssessment2);
        AssertUtil.isTrue(i == 1 && i1 == 1 && i2 == 1,"表4修改数据出现异常,请检查");
        return "修改成功";
    }

    @Override
    public Serious_damage_and_quality_assessmentDTO getTest4(String Case) {
        Serious_damage_and_quality_assessment seriousDamageAndQualityAssessment = seriousDamageAndQualityAssessmentMapper.selTableTime(Case);
        if (seriousDamageAndQualityAssessment == null)return null;
        Serious_damage_and_quality_assessment_1 seriousDamageAndQualityAssessment1 = seriousDamageAndQualityAssessment1Mapper.selTable1(Case);
        Serious_damage_and_quality_assessment_2 seriousDamageAndQualityAssessment2 = seriousDamageAndQualityAssessment2Mapper.selTable2(Case);

        Serious_damage_and_quality_assessmentDTO seriousDamageAndQualityAssessmentDTO = new Serious_damage_and_quality_assessmentDTO();
        CopyUtil.copyClass(seriousDamageAndQualityAssessment,seriousDamageAndQualityAssessmentDTO);
        CopyUtil.copyClass(seriousDamageAndQualityAssessment1,seriousDamageAndQualityAssessmentDTO);
        CopyUtil.copyClass(seriousDamageAndQualityAssessment2,seriousDamageAndQualityAssessmentDTO);

        return seriousDamageAndQualityAssessmentDTO;
    }
}
